/*******************************************************************************

This code file produces Table 3, "Developer Participation Responses to Variation in 421-a Incentive."

*******************************************************************************/

*** Manage settings

	run "$dir/code/modules/settings.do"
	
* Load Stata-TeX

	do "$code/modules/stata-tex.do"
	cd "$tables/estimates"
	
*** Load data

	use "$data/clean/cleaned_data.dta", clear
	
********************************************************************************
* Complete table analysis
********************************************************************************
	
*** Logit, No FE

	logit inclusionary_onsite dtaxrate_onsite, cl(nta)
	store_est_tpl using table3.csv, coef(dtaxrate_onsite) name(logit0) format(%5.2f) all
	
	margins, dydx(dtaxrate_onsite) post
	store_est_tpl using table3.csv, coef(dtaxrate_onsite) format(%5.2f) name(margins0) all
	
	quietly logit inclusionary_onsite dtaxrate_onsite, cl(nta)
	nlcom (sd: 3.14159/(sqrt(3)*_b[dtaxrate_onsite])), post
	store_est_tpl using table3.csv, coef(sd) name(sd0) all
	
*** Logit, borough FEs, expanding controls

	* No controls
	
	logit inclusionary_onsite dtaxrate_onsite i.borough i.yearpermit, cl(nta)
	store_est_tpl using table3.csv, coef(dtaxrate_onsite) name(logit1) format(%5.2f) all
	
	margins, dydx(dtaxrate_onsite) post
	store_est_tpl using table3.csv, coef(dtaxrate_onsite) format(%5.2f) name(margins1) all
	
	quietly logit inclusionary_onsite dtaxrate_onsite i.borough i.yearpermit, cl(nta)
	nlcom (sd: 3.14159/(sqrt(3)*_b[dtaxrate_onsite])), post
	store_est_tpl using table3.csv, coef(sd) name(sd1) all
	
	* Lot controls
	
	logit inclusionary_onsite dtaxrate_onsite $controls_lot i.borough i.yearpermit, cl(nta)
	store_est_tpl using table3.csv, coef(dtaxrate_onsite) name(logit2) format(%5.2f) all
	
	margins, dydx(dtaxrate_onsite) post
	store_est_tpl using table3.csv, coef(dtaxrate_onsite) format(%5.2f) name(margins2) all
	
	quietly logit inclusionary_onsite dtaxrate_onsite $controls_lot i.borough i.yearpermit, cl(nta)
	nlcom (sd: 3.14159/(sqrt(3)*_b[dtaxrate_onsite])), post
	store_est_tpl using table3.csv, coef(sd) name(sd2) all
	
	* Lot + neighborhood controls
	
	logit inclusionary_onsite dtaxrate_onsite $controls_lot $controls_block i.borough i.yearpermit, cl(nta)
	store_est_tpl using table3.csv, coef(dtaxrate_onsite) name(logit3) format(%5.2f) all
	
	margins, dydx(dtaxrate_onsite) post
	store_est_tpl using table3.csv, coef(dtaxrate_onsite) format(%5.2f) name(margins3) all
	
	quietly logit inclusionary_onsite dtaxrate_onsite $controls_lot $controls_block i.borough i.yearpermit, cl(nta)
	nlcom (sd: 3.14159/(sqrt(3)*_b[dtaxrate_onsite])), post
	store_est_tpl using table3.csv, coef(sd) name(sd3) all
	
*** Logit, NTA FEs, expanding controls

	* No controls
	
	logit inclusionary_onsite dtaxrate_onsite i.nta i.yearpermit, cl(nta)
	store_est_tpl using table3.csv, coef(dtaxrate_onsite) name(logit4) format(%5.2f) all
	
	margins, dydx(dtaxrate_onsite) post
	store_est_tpl using table3.csv, coef(dtaxrate_onsite) format(%5.2f) name(margins4) all
	
	quietly logit inclusionary_onsite dtaxrate_onsite i.nta i.yearpermit, cl(nta)
	nlcom (sd: 3.14159/(sqrt(3)*_b[dtaxrate_onsite])), post
	store_est_tpl using table3.csv, coef(sd) name(sd4) all
	
	* Lot controls
	
	logit inclusionary_onsite dtaxrate_onsite $controls_lot i.nta i.yearpermit, cl(nta)
	store_est_tpl using table3.csv, coef(dtaxrate_onsite) name(logit5) format(%5.2f) all
	
	margins, dydx(dtaxrate_onsite) post
	store_est_tpl using table3.csv, coef(dtaxrate_onsite) format(%5.2f) name(margins5) all
	
	quietly logit inclusionary_onsite dtaxrate_onsite $controls_lot i.nta i.yearpermit, cl(nta)
	nlcom (sd: 3.14159/(sqrt(3)*_b[dtaxrate_onsite])), post
	store_est_tpl using table3.csv, coef(sd) name(sd5) all
	
	* Lot + neighborhood controls
	
	logit inclusionary_onsite dtaxrate_onsite $controls_lot $controls_block i.nta i.yearpermit, cl(nta) difficult
	store_est_tpl using table3.csv, coef(dtaxrate_onsite) name(logit6) format(%5.2f) all
	
	margins, dydx(dtaxrate_onsite) post
	store_est_tpl using table3.csv, coef(dtaxrate_onsite) format(%5.2f) name(margins6) all
	
	quietly logit inclusionary_onsite dtaxrate_onsite $controls_lot $controls_block i.nta i.yearpermit, cl(nta) difficult	
	nlcom (sd: 3.14159/(sqrt(3)*_b[dtaxrate_onsite])), post
	store_est_tpl using table3.csv, coef(sd) name(sd6) all
	
********************************************************************************
* Create table
********************************************************************************
	
	cat table3.csv

	cap erase "$tables/table3.tex"

	cd "$code/modules"
	
	capture table_from_tpl, t("$tables/templates/table3.tex") ///
						r("$tables/estimates/table3.csv") ///
						o("$tables/output/table3.tex") 
						
	capture table_from_tpl, t("$tables/templates/table3.tex") ///
						r("$tables/estimates/table3.csv") ///
						o("$tables_overleaf/table3.tex") 
		
		
